// Javascript Document by Vaibhav

// Global Variables
var message;

//=============================Post Message to the wall=====================================
function	putMsg()
{
	// parsing message from text-box.
	message = document.getElementById('msg').value;
	// reseting the value of the text-box.
	document.getElementById('msg').value = "";
	// save message in the database
	save(message);
	// update html table
	putRow(message);	
}

//===============================Insert Row=============================================
function putRow(message)
{
	if(message!=""&&message!=" ")
	{
		// Displaying message
		// Inserting new empty row in the table
		var tbl = document.getElementById('wall').insertRow(1);
		
		//inserting two empty cells
		var mssg = tbl.insertCell(0);
		var rmv  = tbl.insertCell(1);
	
		//Updating the contents of the cells
		mssg.innerHTML = "<b>"+message+"</b>";
		rmv.innerHTML  = " <img src='GUI/del.png' />";
	}		
}

//===============================Delete Message===========================================
function del()
{
	row = whichRow();
	col = whichCol();
	if(col==1)
	{
		remove(row); // Remove Entry from Database
		document.getElementById("wall").deleteRow(row);	// Remove Entry From HTML Page				
	}
}

//===============================Side Functions===============================================
// Function used to detect click-event.
function whichElement()
{
	var e=window.event;    // Catch event		
  	var targ = e.target;  // get object of the elment -- target is a javascript method
   	return targ;         // return object to the calling function
}
// Function returns the Row number
function whichRow()
{
	targ = whichElement();
	row = targ.parentNode.parentNode.rowIndex;
	return row;
}
// Function returns the Column number of the currently selected cell
function whichCol()
{
	targ = whichElement();
	col = targ.parentNode.cellIndex;
	return col;
}